import junit.framework.TestCase;


public class InsertionSorterTest extends TestCase {
	
	protected void setUp() throws Exception {
		super.setUp();
		
	}
	
	public void testSort(){
		Integer[] myNums = {10,5,2,6,3,7,1};
		Integer[] correct    = {1,2,3,5,6,7,10};
		InsertionSorter<Integer> mySorter = new InsertionSorter<Integer>(myNums);
		Comparable<Integer>[] sorted = mySorter.sort();
		System.out.println(ArrayGetter.getPrintedContents(sorted));
		for(int i = 0;i<correct.length;i++){
			assertEquals(correct[i],sorted[i]);
		}
	}
	
	public void testLargeSortTime(){
		Integer[] myNums = ArrayGetter.getIntegerArray("myNumbers");
		InsertionSorter<Integer> mySorter = new InsertionSorter<Integer>(myNums, "output.txt");
		Comparable<Integer>[] sorted = mySorter.sort();
		System.out.println(ArrayGetter.getPrintedContents(sorted));
		
	}
	
	public void testBinarySearch(){
		Integer[] myNums = {1,2,3,4,5,7,8,8,10};
		int pos = InsertionSorter.binarySearch(0, myNums.length, new Integer(6),myNums);
		assertEquals(4,pos);
		pos = InsertionSorter.binarySearch(0, myNums.length, new Integer(9),myNums);
		assertEquals(7,pos);
		pos = InsertionSorter.binarySearch(0, myNums.length, new Integer(7),myNums);
		assertEquals(5,pos);
	}

}
